<template>
	<view>
		<image src="https://huajia-online-1316192331.cos.ap-guangzhou.myqcloud.com/static/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230503141219.png" class="logo"></image>
		<view class="register-container">
			<button class="register-btn" open-type="getUserInfo" @tap="register()">点击注册</button>
		</view>
	</view>
</template>

<script>
export default {
    data() {
        return {
            registerCode: '',
            code: null
        };
    },
    methods: {
        register: function() {
            let that = this;
            uni.login({
                provider: 'weixin',
                success: function(resp) {
                    let code = resp.code;
                    that.code = code;
                }
            });
            uni.getUserProfile({
                desc: '获取用户信息',
                success: function(resp) {
                    let nickName = resp.userInfo.nickName;
                    let avatarUrl = resp.userInfo.avatarUrl;
                    // console.log(nickName);
                    // console.log(avatarUrl);
                    let data = {
                        code: that.code,
                        nickName: nickName,
                        photo: avatarUrl
                    };
                    that.ajax(that.url.register, 'POST', data, function(resp) {
                        let permission = resp.data.permission;
                        let token = resp.data.token;
                        uni.setStorageSync('token', token);
                        uni.setStorageSync('permission', permission);
                        uni.switchTab({
                            url: '../index/index'
                        });
                    });
                }
            });
        }
    }
};

</script>

<style lang="less">
@import url('register.less');
</style>
